<template>
  <div class="app-container">
   <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAddRow"
          v-hasPermi="['system:molding:add']"
          size="small"
        >添加</el-button>
      </el-col>
   </el-row>

  <div class="layoutStyle">
    <div class="leftStyle">
 <!-- 111 -->
   <div class="flexdiv">
    <div class="titleDiv">材料成本  总金额：   {{ showMaterialTotalCost }}  </div>
    <div class="titleDiv"></div>
  </div>
   <el-table v-loading="loading" :data="moldingList"  class="custom-header-table" :class="'small-padding'">
      <!-- <el-table-column type="selection" width="55"  />
      <el-table-column label="主键ID"  prop="id" />
      <el-table-column label="产品ID"  prop="pid" /> -->
       <el-table-column label="序号"  prop="id"  width="50px"/>
      <!-- <el-table-column label="产品类型"  prop="ptype" /> -->
      <el-table-column label="料号"  width="50px" >
        <template #default="{ row }">
          <el-input v-model="row.partNumber" v-if="row.isEditing" size="small"></el-input>
          <span v-else>
             {{ row.partNumber }}
           </span>
        </template>
      </el-table-column>
      <el-table-column label="零件名称"  width="102px">
          <template #default="{ row }">
          <el-input v-model="row.partName" v-if="row.isEditing" size="small"></el-input>
          <span v-else>
          <el-tooltip :content="row.partName" placement="top">
              <div class="ellipsis-cell">{{ row.partName }}</div>
           </el-tooltip>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="材质"  prop="material" width="82px">
        <template #default="{ row }">
          <el-input v-model="row.material" v-if="row.isEditing" size="small"></el-input>
          <span v-else>
            <!-- {{ row.material }} -->

          <el-tooltip :content="row.material" placement="top">
              <div class="ellipsis-cell">{{ row.material }}</div>
           </el-tooltip>


          </span>
        </template>
      </el-table-column>


      <el-table-column label="单位用量" width="60px">
      <el-table-column label="pc" width="60px">
        <template #default="{ row }">
          <el-input v-model.number="row.unitDosage" v-if="row.isEditing" size="small"></el-input>
          <span v-else>{{ row.unitDosage?row.unitDosage:"" }}</span>
        </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="材料单价" width="65px">
         <el-table-column label="(RMB/pc)" width="65px">
         <template #default="{ row }">
          <el-input v-model.number="row.unitPrice" v-if="row.isEditing" size="small"></el-input>
          <span v-else>{{ row.unitPrice?row.unitPrice:"" }}</span>
         </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="净重" width="60px">
         <el-table-column label="(g/pc)" width="60px">
          <template #default="{ row }">
          <el-input v-model.number="row.netWeight" v-if="row.isEditing" size="small"></el-input>
          <span v-else>{{ row.netWeight?row.netWeight:"" }}</span>
        </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="料头重" width="50px">
         <template #default="{ row }">
            <el-input v-model.number="row.materialHeadWeight" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.materialHeadWeight?row.materialHeadWeight:"" }}</span>
          </template>
        </el-table-column>

      <el-table-column label="次料" width="50px">
        <el-table-column label="(%)" width="50px">
          <template #default="{ row }">
            <el-input v-model.number="row.inferiorMaterial" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.inferiorMaterial?row.inferiorMaterial:"" }}</span>
          </template>
          </el-table-column>
        </el-table-column>
      <el-table-column label="废料价格"  width="40px">
          <template #default="{ row }">
            <el-input v-model.number="row.wasteMaterialPrice" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.wasteMaterialPrice?row.wasteMaterialPrice:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="模穴数" width="50px">
         <template #default="{ row }">
            <el-input v-model.number="row.cavitiesNumber" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.cavitiesNumber?row.cavitiesNumber:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="损耗率" width="50px">
        <el-table-column label="(%)"  width="50px">
        <template #default="{ row }">
            <!-- <el-input v-model.number="row.materialWastageRate" v-if="row.isEditing" size="small">
                       <template #suffix>
                          <span class="percentage-suffix">%</span>
                       </template>
            </el-input> -->
              <el-input v-model.number="row.materialWastageRate" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.materialWastageRate?row.materialWastageRate:"" }}</span>
          </template>
          </el-table-column>
       </el-table-column>

      <el-table-column label="不良率"  prop="materialDefectRate" width="50px">
        <el-table-column label="(%)" width="50px">
         <template #default="{ row }">
            <!-- <el-input v-model.number="row.materialDefectRate" v-if="row.isEditing" size="small">
                       <template #suffix>
                          <span class="percentage-suffix">%</span>
                       </template>
            </el-input> -->
               <el-input v-model.number="row.materialDefectRate" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.materialDefectRate?row.materialDefectRate:"" }}</span>
          </template>
        </el-table-column>
       </el-table-column>
     <!-- <el-table-column label="材料其他费用"  prop="materialOtherExpenses">
          <template #default="{ row }">
            <el-input v-model.number="row.materialOtherExpenses" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.materialOtherExpenses?row.materialOtherExpenses:"" }}</span>
          </template>
        </el-table-column> -->
      <el-table-column label="管理费"  width="55px"  prop="materialManagementRate">
          <el-table-column label="占比(%)" width="55px">
          <template #default="{ row }">
            <!-- <el-input v-model.number="row.materialManagementRate" v-if="row.isEditing" size="small">
                       <template #suffix>
                          <span class="percentage-materialManagementRate">%</span>
                       </template>
            </el-input> -->
             <el-input v-model.number="row.materialManagementRate" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.materialManagementRate?row.materialManagementRate:"" }}</span>
          </template>
         </el-table-column>
        </el-table-column>

      <el-table-column label="材料利润"  width="60px" prop="materialProfitRate">
        <el-table-column label="占比(%)" width="60px">
            <template #default="{ row }">
            <!-- <el-input v-model.number="row.materialProfitRate" v-if="row.isEditing" size="small">
                       <template #suffix>
                          <span class="percentage-materialManagementRate">%</span>
                       </template>
            </el-input> -->
             <el-input v-model.number="row.materialProfitRate" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.materialProfitRate?row.materialProfitRate:"" }}</span>
          </template>
          </el-table-column>
        </el-table-column>


      <!-- <el-table-column label="注塑其他"  prop="injectionMoldingOther">
         <template #default="{ row }">
            <el-input v-model="row.injectionMoldingOther" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.injectionMoldingOther?row.injectionMoldingOther:"" }}</span>
          </template>
        </el-table-column> -->

 <!-- <el-table-column label="耗料"  prop="materialConsumer" />
      <el-table-column label="料头损耗率"  prop="headLossRate" />
      <el-table-column label="辅材费用"  prop="auxiliaryCost" />
      <el-table-column label="材料不良费"  prop="materialDefectFee" />
      <el-table-column label="材料成本"  prop="materialCost" />
      <el-table-column label="材料管理费"  prop="materialManagementFee" />
      <el-table-column label="材料利润"  prop="materialProfit" />
      <el-table-column label="材料成本合计"  prop="materialTotalCost" /> -->
      <!-- <el-table-column label="机台型号"  prop="machineModel">
          <template #default="{ row }">
            <el-input v-model="row.machineModel" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.machineModel?row.machineModel:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="模具类型"  prop="moldType">
          <template #default="{ row }">
            <el-input v-model="row.moldType" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.moldType?row.moldType:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="成本率"  prop="costRate">
        <template #default="{ row }">
            <el-input v-model.number="row.costRate" v-if="row.isEditing" size="small">
                       <template #suffix>
                          <span class="percentage-materialManagementRate">%</span>
                       </template>
            </el-input>
            <span v-else>{{ row.costRate?row.costRate:"" }}</span>
          </template>
        </el-table-column>

      <el-table-column label="周期"  prop="period">
        <template #default="{ row }">
            <el-input v-model.number="row.period" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.period?row.period:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="秒/时"  prop="periodUnit">
         <template #default="{ row }">
            <el-input v-model.number="row.periodUnit" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.periodUnit?row.periodUnit:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="效率"  prop="efficiency">
         <template #default="{ row }">
            <el-input v-model.number="row.efficiency" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.efficiency?row.efficiency:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="模具维修天数"  prop="moldFixDays">
         <template #default="{ row }">
            <el-input v-model.number="row.moldFixDays" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.moldFixDays?row.moldFixDays:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="模具维修费用"  prop="moldFixCost">
          <template #default="{ row }">
            <el-input v-model.number="row.moldFixCost" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.moldFixCost?row.moldFixCost:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="模具维修其他费用"  prop="moldFixOtherCost">
           <template #default="{ row }">
            <el-input v-model.number="row.moldFixOtherCost" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.moldFixOtherCost?row.moldFixOtherCost:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="模具工时不良率"  prop="moldDefectRate">
          <template #default="{ row }">
            <el-input v-model.number="row.moldDefectRate" v-if="row.isEditing" size="small">
              <template #suffix>
                <span class="percentage-moldDefectRate">%</span>
              </template>
            </el-input>
            <span v-else>{{ row.moldDefectRate?row.moldDefectRate:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="模具注塑其他费用"  prop="moldInjectionOtherCost">
            <template #default="{ row }">
            <el-input v-model.number="row.moldInjectionOtherCost" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.moldInjectionOtherCost?row.moldInjectionOtherCost:"" }}</span>
          </template>
       </el-table-column>
      <el-table-column label="模具注塑管理费占比"  prop="moldInjectionManagementRate">
          <template #default="{ row }">
            <el-input v-model.number="row.moldInjectionManagementRate" v-if="row.isEditing" size="small">
              <template #suffix>
                <span class="percentage-moldInjectionManagementRate">%</span>
              </template>
            </el-input>
            <span v-else>{{ row.moldInjectionManagementRate?row.moldInjectionManagementRate:"" }}</span>
          </template>
       </el-table-column>
      <el-table-column label="模具注塑利润占比"  prop="moldInjectionProfitRate">
          <template #default="{ row }">
            <el-input v-model.number="row.moldInjectionProfitRate" v-if="row.isEditing" size="small">
              <template #suffix>
                <span class="percentage-moldInjectionProfitRate">%</span>
              </template>
            </el-input>
            <span v-else>{{ row.moldInjectionProfitRate?row.moldInjectionProfitRate:"" }}</span>
          </template>
       </el-table-column>
      <el-table-column label="模具注塑利润占比"  prop="moldFixCostPcs">
          <template #default="{ row }">
            <el-input v-model.number="row.moldFixCostPcs" v-if="row.isEditing" size="small">
              <template #suffix>
                <span class="percentage-moldFixCostPcs">%</span>
              </template>
            </el-input>
            <span v-else>{{ row.moldFixCostPcs?row.moldFixCostPcs:"" }}</span>
          </template>
       </el-table-column> -->
      <!-- <el-table-column label="模具加工不良费用"  prop="moldDefectCost" />
      <el-table-column label="模具注塑成本"  prop="moldInjectionCost" />
      <el-table-column label="模具注塑管理费"  prop="moldInjectionManagementCost" />
      <el-table-column label="模具利润"  prop="moldProfit" />
      <el-table-column label="注塑成本合计"  prop="moldTotalCost" /> -->
      <!-- <el-table-column label="工站名称"  prop="workstation">
          <template #default="{ row }">
            <el-input v-model="row.workstation" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.workstation?row.workstation:"" }}</span>
          </template>
       </el-table-column>
      <el-table-column label="注塑工程师人力"  prop="injectionEngineerCount">
          <template #default="{ row }">
            <el-input v-model="row.injectionEngineerCount" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.injectionEngineerCount?row.injectionEngineerCount:"" }}</span>
          </template>
       </el-table-column>
      <el-table-column label="注塑工程师工费率"  prop="injectionEngineerRate">
         <template #default="{ row }">
            <el-input v-model.number="row.injectionEngineerRate" v-if="row.isEditing" size="small">
             <template #suffix>
                <span class="percentage-materialManagementRate">%</span>
              </template>
            </el-input>
            <span v-else>{{ row.injectionEngineerRate?row.injectionEngineerRate:"" }}</span>
          </template>
        </el-table-column> -->
      
      <!-- <el-table-column label="工时"  prop="laborHours" />
      <el-table-column label="人工费"  prop="laborCost" />
      <el-table-column label="总成本"  prop="totalCost" />
      <el-table-column label="产能"  prop="capacityKpcsPerDay" /> -->
      <el-table-column label="材料成本合计"  prop="materialTotalCost" width="100px"/>
      <!-- <el-table-column label="操作"  class-name="small-padding fixed-width" width="140" fixed="right"> -->
          <!-- <template #default="{ row, $index }"> -->
            <!-- <el-button 
              v-if="!row.isEditing" 
              link 
              type="primary" 
              icon="Edit"
              @click="startEdit($index)"
              >编辑</el-button>
            
            <el-button 
              v-else 
              size="small" 
              type="success" 
              @click="saveEdit($index)"
              style="width: 50px"
            >保存</el-button>
            
            <el-button 
              v-if="row.isEditing" 
              size="small" 
              type="primary"
              @click="cancelEdit($index)"
              style="width: 50px"
            >取消</el-button>
             <el-button 
                v-if="!row.isEditing" 
                 link 
                type="primary" 
                icon="Delete"
                @click="handleDelete(row)"
              >删除</el-button>

            </template> -->
       <!-- <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:molding:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:molding:remove']">删除</el-button>
        </template> -->

      <!-- </el-table-column> -->
    </el-table>

<!--222-->
<div class="flexdiv">
<div class="titleDiv">注塑工时成本  总金额:{{ showMoldingCost.toFixed(6) }} </div>
<div class="titleDiv">  {{ showMoldingCost.toFixed(6) }}</div>
</div>

<el-table v-loading="loading" :data="moldingList"  class="custom-header-table" :class="'small-padding'">
      <!-- <el-table-column type="selection" width="55"  />
      <el-table-column label="主键ID"  prop="id" />
      <el-table-column label="产品ID"  prop="pid" /> -->
       <el-table-column label="序号"  prop="id"  width="50px"/>
      <!-- <el-table-column label="产品类型"  prop="ptype" /> -->
      <el-table-column label="料号"  width="50px" >
        <template #default="{ row }">
          <el-input v-model="row.partNumber" v-if="row.isEditing" size="small"></el-input>
          <span v-else>{{ row.partNumber }}</span>
        </template>
      </el-table-column>
       <el-table-column label="零件名称"  width="100px">
          <template #default="{ row }">
          <el-input v-model="row.partName" v-if="row.isEditing" size="small"></el-input>
          <span v-else>
            <!-- {{ row.partName }} -->
          <el-tooltip :content="row.partName" placement="top">
              <div class="ellipsis-cell">{{ row.partName }}</div>
           </el-tooltip>
        </span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="材质"  prop="material" width="250px">
        <template #default="{ row }">
          <el-input v-model="row.material" v-if="row.isEditing" size="small"></el-input>
          <span v-else>{{ row.material }}</span>
        </template>
      </el-table-column> -->


      <!-- <el-table-column label="单位用量">
      <el-table-column label="pc">
        <template #default="{ row }">
          <el-input v-model.number="row.unitDosage" v-if="row.isEditing" size="small"></el-input>
          <span v-else>{{ row.unitDosage?row.unitDosage:"" }}</span>
        </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="材料单价">
         <el-table-column label="(RMB/pc)">
         <template #default="{ row }">
          <el-input v-model.number="row.unitPrice" v-if="row.isEditing" size="small"></el-input>
          <span v-else>{{ row.unitPrice?row.unitPrice:"" }}</span>
         </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="净重">
         <el-table-column label="(g/pc)">
          <template #default="{ row }">
          <el-input v-model.number="row.netWeight" v-if="row.isEditing" size="small"></el-input>
          <span v-else>{{ row.netWeight?row.netWeight:"" }}</span>
        </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="料头重">
         <template #default="{ row }">
            <el-input v-model.number="row.materialHeadWeight" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.materialHeadWeight?row.materialHeadWeight:"" }}</span>
          </template>
        </el-table-column> -->

      <!-- <el-table-column label="次料">
        <el-table-column label="(%)">
          <template #default="{ row }">
            <el-input v-model.number="row.inferiorMaterial" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.inferiorMaterial?row.inferiorMaterial:"" }}</span>
          </template>
          </el-table-column>
        </el-table-column>
      <el-table-column label="废料价格">
          <template #default="{ row }">
            <el-input v-model.number="row.wasteMaterialPrice" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.wasteMaterialPrice?row.wasteMaterialPrice:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="模穴数">
         <template #default="{ row }">
            <el-input v-model.number="row.cavitiesNumber" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.cavitiesNumber?row.cavitiesNumber:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="材料损耗率" width="90px">
        <el-table-column label="(%)"  width="90px">
        <template #default="{ row }">
            <el-input v-model.number="row.materialWastageRate" v-if="row.isEditing" size="small">
                       <template #suffix>
                          <span class="percentage-suffix">%</span>
                       </template>
            </el-input>
            <span v-else>{{ row.materialWastageRate?row.materialWastageRate:"" }}</span>
          </template>
          </el-table-column>
       </el-table-column>

      <el-table-column label="不良率"  prop="materialDefectRate">
        <el-table-column label="(%)">
         <template #default="{ row }">
            <el-input v-model.number="row.materialDefectRate" v-if="row.isEditing" size="small">
                       <template #suffix>
                          <span class="percentage-suffix">%</span>
                       </template>
            </el-input>
            <span v-else>{{ row.materialDefectRate?row.materialDefectRate:"" }}</span>
          </template>
        </el-table-column>
       </el-table-column> -->
     <!-- <el-table-column label="材料其他费用"  prop="materialOtherExpenses">
          <template #default="{ row }">
            <el-input v-model.number="row.materialOtherExpenses" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.materialOtherExpenses?row.materialOtherExpenses:"" }}</span>
          </template>
        </el-table-column> -->
      <!-- <el-table-column label="材料管理费"  width="90px"  prop="materialManagementRate">
          <el-table-column label="占比(%)" width="90px">
          <template #default="{ row }">
            <el-input v-model.number="row.materialDefectRate" v-if="row.isEditing" size="small">
                       <template #suffix>
                          <span class="percentage-materialManagementRate">%</span>
                       </template>
            </el-input>
            <span v-else>{{ row.materialManagementRate?row.materialManagementRate:"" }}</span>
          </template>
         </el-table-column>
        </el-table-column>

      <el-table-column label="材料利润"  width="80px" prop="materialProfitRate">
        <el-table-column label="占比(%)" width="80px">
            <template #default="{ row }">
            <el-input v-model.number="row.materialProfitRate" v-if="row.isEditing" size="small">
                       <template #suffix>
                          <span class="percentage-materialManagementRate">%</span>
                       </template>
            </el-input>
            <span v-else>{{ row.materialProfitRate?row.materialProfitRate:"" }}</span>
          </template>
          </el-table-column>
        </el-table-column> -->


      <!-- <el-table-column label="注塑其他"  prop="injectionMoldingOther">
         <template #default="{ row }">
            <el-input v-model="row.injectionMoldingOther" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.injectionMoldingOther?row.injectionMoldingOther:"" }}</span>
          </template>
        </el-table-column> -->

 <!-- <el-table-column label="耗料"  prop="materialConsumer" />
      <el-table-column label="料头损耗率"  prop="headLossRate" />
      <el-table-column label="辅材费用"  prop="auxiliaryCost" />
      <el-table-column label="材料不良费"  prop="materialDefectFee" />
      <el-table-column label="材料成本"  prop="materialCost" />
      <el-table-column label="材料管理费"  prop="materialManagementFee" />
      <el-table-column label="材料利润"  prop="materialProfit" />
      <el-table-column label="材料成本合计"  prop="materialTotalCost" /> -->
      <el-table-column label="机台型号"  prop="machineModel">
          <template #default="{ row }">
            <el-input v-model="row.machineModel" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.machineModel?row.machineModel:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="模具类型"  prop="moldType">
        
          <template #default="{ row }">
            <el-input v-model="row.moldType" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.moldType?row.moldType:"" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="成本率"  prop="costRate">
         <el-table-column label="(RMB/H)" width="80px">
            <template #default="{ row }">
              <el-input v-model.number="row.costRate" v-if="row.isEditing" size="small">
                        <template #suffix>
                            <span class="percentage-materialManagementRate">%</span>
                        </template>
              </el-input>
              <span v-else>{{ row.costRate?row.costRate:"" }}</span>
            </template>
        </el-table-column>
       </el-table-column>
      <el-table-column label="周期"  prop="period">
         <el-table-column label="(S/Cycle)" width="80px">
        <template #default="{ row }">
            <el-input v-model.number="row.period" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.period?row.period:"" }}</span>
          </template>
          </el-table-column>
        </el-table-column>
      <!-- <el-table-column label="秒/时"  prop="periodUnit">
         <template #default="{ row }">
            <el-input v-model.number="row.periodUnit" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.periodUnit?row.periodUnit:"" }}</span>
          </template>
        </el-table-column> -->
      <el-table-column label="效率"  prop="efficiency">
        <el-table-column label="(%)" width="80px">
         <template #default="{ row }">
            <el-input v-model.number="row.efficiency" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.efficiency?row.efficiency:"" }}</span>
          </template>
          </el-table-column>
        </el-table-column>
      <!-- <el-table-column label="模具维修天数"  prop="moldFixDays">
         <template #default="{ row }">
            <el-input v-model.number="row.moldFixDays" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.moldFixDays?row.moldFixDays:"" }}</span>
          </template>
        </el-table-column> -->
      <!-- <el-table-column label="模具维修费用"  prop="moldFixCost">
          <template #default="{ row }">
            <el-input v-model.number="row.moldFixCost" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.moldFixCost?row.moldFixCost:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="模具维修其他费用"  prop="moldFixOtherCost">
           <template #default="{ row }">
            <el-input v-model.number="row.moldFixOtherCost" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.moldFixOtherCost?row.moldFixOtherCost:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="模具工时不良率"  prop="moldDefectRate">
          <template #default="{ row }">
            <el-input v-model.number="row.moldDefectRate" v-if="row.isEditing" size="small">
              <template #suffix>
                <span class="percentage-moldDefectRate">%</span>
              </template>
            </el-input>
            <span v-else>{{ row.moldDefectRate?row.moldDefectRate:"" }}</span>
          </template>
        </el-table-column>
      <el-table-column label="模具注塑其他费用"  prop="moldInjectionOtherCost">
            <template #default="{ row }">
            <el-input v-model.number="row.moldInjectionOtherCost" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.moldInjectionOtherCost?row.moldInjectionOtherCost:"" }}</span>
          </template>
       </el-table-column> -->
      <el-table-column label="管理费占比"  prop="moldInjectionManagementRate" width="100px">
      <el-table-column label="(RMB/PC) %" width="100px">
          <template #default="{ row }">
            <el-input v-model.number="row.moldInjectionManagementRate" v-if="row.isEditing" size="small">
              <template #suffix>
                <span class="percentage-moldInjectionManagementRate">%</span>
              </template>
            </el-input>
            <span v-else>{{ row.moldInjectionManagementRate?row.moldInjectionManagementRate:"" }}</span>
          </template>
          </el-table-column>
       </el-table-column>
      <el-table-column label="利润占比"  prop="moldInjectionProfitRate"  width="100px">
        <el-table-column label="(RMB/PC) %"  width="100px">
          <template #default="{ row }">
            <el-input v-model.number="row.moldInjectionProfitRate" v-if="row.isEditing" size="small">
              <template #suffix>
                <span class="percentage-moldInjectionProfitRate">%</span>
              </template>
            </el-input>
            <span v-else>{{ row.moldInjectionProfitRate?row.moldInjectionProfitRate:"" }}</span>
          </template>
        </el-table-column>
       </el-table-column>
      <!-- <el-table-column label=" 模具维修费用/pcs"  prop="moldFixCostPcs">
          <template #default="{ row }">
            <el-input v-model.number="row.moldFixCostPcs" v-if="row.isEditing" size="small">
              <template #suffix>
                <span class="percentage-moldFixCostPcs">%</span>
              </template>
            </el-input>
            <span v-else>{{ row.moldFixCostPcs?row.moldFixCostPcs:"" }}</span>
          </template>
       </el-table-column>  -->
      <!-- <el-table-column label="模具加工不良费用"  prop="moldDefectCost" />
      <el-table-column label="模具注塑成本"  prop="moldInjectionCost" />
      <el-table-column label="模具注塑管理费"  prop="moldInjectionManagementCost" />
      <el-table-column label="模具利润"  prop="moldProfit" />
      <el-table-column label="注塑成本合计"  prop="moldTotalCost" /> -->
      <!-- <el-table-column label="工站名称"  prop="workstation">
          <template #default="{ row }">
            <el-input v-model="row.workstation" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.workstation?row.workstation:"" }}</span>
          </template>
       </el-table-column>
      <el-table-column label="注塑工程师人力"  prop="injectionEngineerCount">
          <template #default="{ row }">
            <el-input v-model="row.injectionEngineerCount" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.injectionEngineerCount?row.injectionEngineerCount:"" }}</span>
          </template>
       </el-table-column>
      <el-table-column label="注塑工程师工费率"  prop="injectionEngineerRate">
         <template #default="{ row }">
            <el-input v-model.number="row.injectionEngineerRate" v-if="row.isEditing" size="small">
             <template #suffix>
                <span class="percentage-materialManagementRate">%</span>
              </template>
            </el-input>
            <span v-else>{{ row.injectionEngineerRate?row.injectionEngineerRate:"" }}</span>
          </template>
        </el-table-column> -->
      
      <!-- <el-table-column label="工时"  prop="laborHours" />
      <el-table-column label="人工费"  prop="laborCost" />
      <el-table-column label="总成本"  prop="totalCost" />
      <el-table-column label="产能"  prop="capacityKpcsPerDay" /> -->
      <el-table-column label="注塑成本合计"  prop="moldTotalCost" width="130"/>
      <!-- <el-table-column label="操作"  class-name="small-padding fixed-width" width="140" fixed="right">
          <template #default="{ row, $index }">
            <el-button 
              v-if="!row.isEditing" 
              link 
              type="primary" 
              icon="Edit"
              @click="startEdit($index)"
              >编辑</el-button>
            
            <el-button 
              v-else 
              size="small" 
              type="success" 
              @click="saveEdit($index)"
              style="width: 50px"
            >保存</el-button>
            
            <el-button 
              v-if="row.isEditing" 
              size="small" 
              type="primary"
              @click="cancelEdit($index)"
              style="width: 50px"
            >取消</el-button>
             <el-button 
                v-if="!row.isEditing" 
                 link 
                type="primary" 
                icon="Delete"
                @click="handleDelete(row)"
              >删除</el-button>
        </template>


      </el-table-column> -->
    </el-table>
<!--333-->
<div class="flexdiv">
<div class="titleDiv">人工成本  总金额：{{ showLaborCost.toFixed(6) }} </div>
<div class="titleDiv"></div>
</div>
<el-table v-loading="loading" :data="moldingList"  class="custom-header-table">
      <!-- <el-table-column type="selection" width="55"  />
      <el-table-column label="主键ID"  prop="id" />
      <el-table-column label="产品ID"  prop="pid" /> -->
       <el-table-column label="序号"  prop="id"  width="60px"/>
      <!-- <el-table-column label="产品类型"  prop="ptype" /> -->
      <el-table-column label="料号"  width="50px" >
        <template #default="{ row }">
          <el-input v-model="row.partNumber" v-if="row.isEditing" size="small"></el-input>
          <span v-else>{{ row.partNumber }}</span>
        </template>
      </el-table-column>
      <el-table-column label="零件名称"  width="200px">
          <template #default="{ row }">
          <el-input v-model="row.partName" v-if="row.isEditing" size="small"></el-input>
          <span v-else>{{ row.partName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="工站名称"  prop="workstation">
          <template #default="{ row }">
            <el-input v-model="row.workstation" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.workstation?row.workstation:"" }}</span>
          </template>
       </el-table-column>
      <el-table-column label="人力"  prop="injectionEngineerCount" style="background-color: brown;">
         <el-table-column label="(人力)" width="120px">
          <template #default="{ row }">
            <el-input v-model="row.injectionEngineerCount" v-if="row.isEditing" size="small"></el-input>
            <span v-else>{{ row.injectionEngineerCount?row.injectionEngineerCount:"" }}</span>
          </template>
          </el-table-column>
       </el-table-column>
      <el-table-column label="工费率"  prop="injectionEngineerRate">
         <el-table-column label="(RMB/人/H)" width="100px">
         <template #default="{ row }">
            <el-input v-model.number="row.injectionEngineerRate" v-if="row.isEditing" size="small">
             <template #suffix>
                <span class="percentage-materialManagementRate">%</span>
              </template>
            </el-input>
            <span v-else>{{ row.injectionEngineerRate?row.injectionEngineerRate:"" }}</span>
          </template>
          </el-table-column>
        </el-table-column>
      
      <!-- <el-table-column label="工时"  prop="laborHours" />
      <el-table-column label="人工费"  prop="laborCost" />
      <el-table-column label="总成本"  prop="totalCost" />
      <el-table-column label="产能"  prop="capacityKpcsPerDay" /> -->
      <el-table-column label="人工费"  prop="totalCost">
         <el-table-column label="(RMB/PCS)" width="100px">
           <template #default="{ row }">
          {{ row.laborCost?row.laborCost:"" }}
          </template>
         </el-table-column>
      </el-table-column>
     <el-table-column label="总费用"  prop="workstation">
          <template #default="{ row }">
               {{ row.totalCost?row.totalCost:"" }}
          </template>
     </el-table-column>


      <el-table-column label="操作"  class-name="small-padding fixed-width" width="140" fixed="right">
          <template #default="{ row, $index }">
            <el-button 
              v-if="!row.isEditing" 
              link 
              type="primary" 
              icon="Edit"
              @click="startEdit($index)"
              >编辑</el-button>
            
            <el-button 
              v-else 
              size="small" 
              type="success" 
              @click="saveEdit($index)"
              style="width: 50px"
            >保存</el-button>
            
            <el-button 
              v-if="row.isEditing" 
              size="small" 
              type="primary"
              @click="cancelEdit($index)"
              style="width: 50px"
            >取消</el-button>
            <el-button 
                v-if="!row.isEditing" 
                 link 
                type="primary" 
                icon="Delete"
                @click="handleDelete(row)"
              >删除</el-button>
           </template>
</el-table-column>
    </el-table>

<!-- 444 -->
<div class="flexdiv">
<div class="titleDiv">总成本：{{ (showLaborCost+showMoldingCost+showMaterialTotalCost).toFixed(6)}}</div>
<div class="titleDiv"></div>
</div>

<el-table v-loading="loading" :data="moldingList"  class="custom-header-table">
      <!-- <el-table-column type="selection" width="55"  />
      <el-table-column label="主键ID"  prop="id" />
      <el-table-column label="产品ID"  prop="pid" /> -->
       <el-table-column label="序号"  prop="id"  width="60px"/>
      <el-table-column label="料号"  width="50px" >
        <template #default="{ row }">
          <el-input v-model="row.partNumber" v-if="row.isEditing" size="small"></el-input>
          <span v-else>{{ row.partNumber }}</span>
        </template>
      </el-table-column>

       <el-table-column label="零件名称"  width="100px">
          <template #default="{ row }">
          <el-input v-model="row.partName" v-if="row.isEditing" size="small"></el-input>
          <span v-else>
            <!-- {{ row.partName }} -->
          <el-tooltip :content="row.partName" placement="top">
              <div class="ellipsis-cell">{{ row.partName }}</div>
           </el-tooltip>
        </span>
        </template>
      </el-table-column>

     <el-table-column label="材料成本合计"  prop="materialTotalCost" width="120px"/>
      <el-table-column label="注塑成本合计1111"  prop="moldTotalCost" width="120px"/>
       <el-table-column label="人工费(RMB/PCS)1111"  prop="totalCost" width="200px">
          <template #default="{ row }">
           {{ row.laborCost?row.laborCost:"" }}
          </template>
        </el-table-column>
       <el-table-column label="总费用"  prop="workstation">
          <template #default="{ row }">
               {{ row.totalCost?row.totalCost:"" }}
          </template>
       </el-table-column>


    </el-table>



    <!-- 添加或修改注塑件成本对话框 -->
    <el-dialog :title="title"  v-model="open" width="1500px" append-to-body>
      <div class = "dialog-content">
            <el-form ref="moldingRef" :model="form" :rules="rules" label-width="150px">
              <el-row :gutter="20">
               <el-col :span="12">
                 <el-form-item label="产品ID" prop="pid">
                  <el-input v-model="form.pid" placeholder="请输入产品ID" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="料号" prop="partNumber">
                  <el-input v-model="form.partNumber" placeholder="请输入料号" />
                </el-form-item>
                </el-col>
                  </el-row>

              <el-row :gutter="20">
                <el-col :span="12">
              <el-form-item label="零件名称" prop="partName">
                <el-input v-model="form.partName" placeholder="请输入零件名称" />
              </el-form-item>
               </el-col>
              <el-col :span="12">
              <el-form-item label="材质" prop="material">
                <el-input v-model="form.material" placeholder="请输入材质" />
              </el-form-item>
              </el-col>
              </el-row>

              <el-row :gutter="20">
                <el-col :span="12">
              <el-form-item label="单位用量" prop="unitDosage">
                <el-input v-model="form.unitDosage" placeholder="请输入单位用量" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="材料单价" prop="unitPrice">
                <el-input v-model="form.unitPrice" placeholder="请输入材料单价" />
              </el-form-item>
              </el-col>
            </el-row>

              <el-row :gutter="20">
                 <el-col :span="12">
              <el-form-item label="净重" prop="netWeight">
                <el-input v-model="form.netWeight" placeholder="请输入净重" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="料头重" prop="materialHeadWeight">
                <el-input v-model="form.materialHeadWeight" placeholder="请输入料头重" />
              </el-form-item>
              </el-col>
              </el-row>

              <el-row :gutter="20">
              <el-col :span="12">
              <el-form-item label="次料" prop="inferiorMaterial">
                <el-input v-model="form.inferiorMaterial" placeholder="请输入次料" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="废料价格" prop="wasteMaterialPrice">
                <el-input v-model="form.wasteMaterialPrice" placeholder="请输入废料价格" />
              </el-form-item>
               </el-col>
                </el-row>

              <el-row :gutter="20">
                <el-col :span="12">
                  <el-form-item label="模穴数" prop="cavitiesNumber">
                    <el-input v-model="form.cavitiesNumber" placeholder="请输入模穴数" />
                  </el-form-item>
              </el-col>
              <el-col :span="12">
                  <el-form-item label="材料损耗率" prop="materialWastageRate">
                    <el-input v-model="form.materialWastageRate" placeholder="请输入材料损耗率" >
                       <template #suffix>
                          <span class="percentage-suffix">%</span>
                       </template>
                    </el-input>
                  </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="20">
              <el-col :span="12">
              <el-form-item label="材料不良率" prop="materialDefectRate">
                <el-input v-model="form.materialDefectRate" placeholder="请输入材料不良率" >
                  <template #suffix>
                    <span class="percentage-suffix">%</span>
                  </template>
                  </el-input>
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="材料其他费用" prop="materialOtherExpenses">
                <el-input v-model="form.materialOtherExpenses" placeholder="请输入材料其他费用" />
              </el-form-item>
              </el-col>
              </el-row>

              <el-row :gutter="20">
                <el-col :span="12">
              <el-form-item label="材料管理费占比" prop="materialManagementRate">
                <el-input v-model="form.materialManagementRate" placeholder="请输入材料管理费占比" />
              </el-form-item>
               </el-col>
              <el-col :span="12">
              <el-form-item label="材料利润占比" prop="materialProfitRate">
                <el-input v-model="form.materialProfitRate" placeholder="请输入材料利润占比" />
              </el-form-item>
              </el-col>
             </el-row>
              <!-- <el-row :gutter="20"> -->


              <!-- <el-form-item label="耗料" prop="materialConsumer">
                <el-input v-model="form.materialConsumer" placeholder="请输入耗料" disabled />
              </el-form-item>
              <el-form-item label="料头损耗率" prop="headLossRate">
                <el-input v-model="form.headLossRate" placeholder="请输入料头损耗率"  disabled  />
              </el-form-item>
              <el-form-item label="辅材费用" prop="auxiliaryCost">
                <el-input v-model="form.auxiliaryCost" placeholder="请输入辅材费用" disabled  />
              </el-form-item> -->
                    <!-- </el-row> -->
              <!-- <el-row :gutter="20">

            <el-form-item label="材料不良费" prop="materialDefectFee">
                <el-input v-model="form.materialDefectFee" placeholder="请输入材料不良费" disabled  />
              </el-form-item>
              <el-form-item label="材料成本" prop="materialCost">
                <el-input v-model="form.materialCost" placeholder="请输入材料成本" disabled />
              </el-form-item>
              <el-form-item label="材料管理费" prop="materialManagementFee">
                <el-input v-model="form.materialManagementFee" placeholder="请输入材料管理费" disabled />
              </el-form-item>
              <el-form-item label="材料利润" prop="materialProfit">
                <el-input v-model="form.materialProfit" placeholder="请输入材料利润" disabled />
              </el-form-item>
                    </el-row> -->
              <el-row :gutter="20">
              <!-- <el-form-item label="材料成本合计" prop="materialTotalCost">
              <el-input v-model="form.materialTotalCost" placeholder="请输入材料成本合计" disabled />
              </el-form-item> -->
              <el-col :span="12">
              <el-form-item label="注塑其他" prop="injectionMoldingOther">
                <el-input v-model="form.injectionMoldingOther"  placeholder="请输入内容" />
              </el-form-item>
                </el-col>
              <el-col :span="12">
              <el-form-item label="机台型号" prop="machineModel">
                <el-input v-model="form.machineModel" placeholder="请输入机台型号" />
              </el-form-item>
              </el-col>
                </el-row>

              <el-row :gutter="20">
              <el-col :span="12">
              <el-form-item label="成本率" prop="costRate">
                <el-input v-model="form.costRate" placeholder="请输入成本率">
                  <template #suffix>
                    <span class="percentage-suffix">%</span>
                  </template>
                  </el-input>
              </el-form-item>
                </el-col>
              <el-col :span="12">
              <el-form-item label="周期" prop="period">
                <el-input v-model="form.period" placeholder="请输入周期" />
              </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="12">
              <el-form-item label="秒/时" prop="periodUnit">
                <el-input v-model="form.periodUnit" placeholder="请输入秒/时" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="效率" prop="efficiency">
                <el-input v-model="form.efficiency" placeholder="请输入效率">
                      <template #suffix>
                    <span class="percentage-suffix">%</span>
                  </template>
                </el-input>
              </el-form-item>
              </el-col>
                </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
              <el-form-item label="模具维修天数" prop="moldFixDays">
                <el-input v-model="form.moldFixDays" placeholder="请输入模具维修天数" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="模具维修费用" prop="moldFixCost">
                <el-input v-model="form.moldFixCost" placeholder="请输入模具维修费用" />
              </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="12">
              <el-form-item label="模具维修其他费用" prop="moldFixOtherCost">
                <el-input v-model="form.moldFixOtherCost" placeholder="请输入模具维修其他费用" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="模具工时不良率" prop="moldDefectRate">
                <el-input v-model="form.moldDefectRate" placeholder="请输入模具工时不良率">
                  <template #suffix>
                    <span class="percentage-suffix">%</span>
                  </template>
                </el-input>
              </el-form-item>
              </el-col>
                </el-row>

              <el-row :gutter="20">
              <el-col :span="12">
              <el-form-item label="模具注塑其他费用" prop="moldInjectionOtherCost">
                <el-input v-model="form.moldInjectionOtherCost" placeholder="请输入模具注塑其他费用" />
              </el-form-item>
               </el-col>
              <el-col :span="12">
              <el-form-item label="模具注塑管理费占比" prop="moldInjectionManagementRate">
                <el-input v-model="form.moldInjectionManagementRate" placeholder="请输入模具注塑管理费占比">
                    <template #suffix>
                    <span class="percentage-suffix">%</span>
                  </template>
                </el-input>
              </el-form-item>
               </el-col>
            </el-row>
           <!-- <el-form-item label="模具维修费用/pcs" prop="moldFixCostPcs">
                <el-input v-model="form.moldFixCostPcs" placeholder="请输入模具维修费用/pcs" disabled />
              </el-form-item>
              <el-form-item label="模具加工不良费用" prop="moldDefectCost">
                <el-input v-model="form.moldDefectCost" placeholder="请输入模具加工不良费用" disabled />
              </el-form-item>
              <el-form-item label="模具注塑成本" prop="moldInjectionCost">
                <el-input v-model="form.moldInjectionCost" placeholder="请输入模具注塑成本" disabled />
              </el-form-item> -->
                    <!-- </el-row> -->
              <!-- <el-row :gutter="20"> -->

            <!-- <el-form-item label="模具注塑管理费" prop="moldInjectionManagementCost">
                <el-input v-model="form.moldInjectionManagementCost" placeholder="请输入模具注塑管理费" disabled/>
              </el-form-item> -->
              <!-- <el-form-item label="模具利润" prop="moldProfit">
                <el-input v-model="form.moldProfit" placeholder="请输入模具利润" disabled/>
              </el-form-item>
              <el-form-item label="注塑成本合计" prop="moldTotalCost">
                <el-input v-model="form.moldTotalCost" placeholder="请输入注塑成本合计" disabled/>
              </el-form-item> -->
         
              <el-row :gutter="20">
                <el-col :span="12">
              <el-form-item label="模具注塑利润占比" prop="moldInjectionProfitRate">
                <el-input v-model="form.moldInjectionProfitRate" placeholder="请输入模具注塑利润占比">
                    <template #suffix>
                    <span class="percentage-suffix">%</span>
                  </template>
                </el-input>
              </el-form-item>
                  </el-col>
              <el-col :span="12">
              <el-form-item label="工站名称" prop="workstation">
                <el-input v-model="form.workstation" placeholder="请输入工站名称" />
              </el-form-item>
              </el-col>
                </el-row>

              <el-row :gutter="20">
                <el-col :span="12">
              <el-form-item label="注塑工程师人力" prop="injectionEngineerCount">
                <el-input v-model="form.injectionEngineerCount" placeholder="请输入注塑工程师人力" />
              </el-form-item>
                  </el-col>
              <el-col :span="12">
              <el-form-item label="注塑工程师工费率" prop="injectionEngineerRate">
                <el-input v-model="form.injectionEngineerRate" placeholder="请输入注塑工程师工费率">
                    <template #suffix>
                    <span class="percentage-suffix">%</span>
                  </template>
                </el-input>
                </el-form-item>
              </el-col>
              </el-row>
              <!-- <el-row :gutter="20">
              <el-col :span="12">
              <el-form-item label="工时" prop="laborHours">
                <el-input v-model="form.laborHours" placeholder="请输入工时" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="人工费" prop="laborCost">
                <el-input v-model="form.laborCost" placeholder="请输入人工费" />
              </el-form-item>
                </el-col>
                </el-row>
              <el-row :gutter="20">
              <el-col :span="12">
              <el-form-item label="总成本" prop="totalCost">
                <el-input v-model="form.totalCost" placeholder="请输入总成本" />
              </el-form-item>
                  </el-col>
              <el-col :span="12">
              <el-form-item label="产能" prop="capacityKpcsPerDay">
                <el-input v-model="form.capacityKpcsPerDay" placeholder="请输入产能" />
              </el-form-item>
                </el-col>
              </el-row> -->
            </el-form>
      <hr color="#f3f3f3" margin-top="20px"/>
       <div class="calculate">
          <el-row :gutter="20">
            <el-col :span="4">
            耗料: {{ consumerMaterial }}
            </el-col>
            <el-col :span="20">
              <!-- 计算公式：{如果模穴数不空} ({净重}+{料头重}/{模穴数})*(1+{材料损耗率}+{材料不良率})*(1-{次料})  如果模穴数为空 结果为“ ”  -->
              计算公式："(净重{{ data.form.netWeight }}+料头重{{ data.form.materialHeadWeight }}/模穴数{{ data.form.cavitiesNumber }})*(1+材料损耗率{{ data.form.materialDefectRate }}+材料不良率{{ data.form.materialDefectRate }})*(1-次料{{ data.form.inferiorMaterial }})"
            </el-col>
          </el-row>

          <el-row :gutter="20">
            <el-col :span="4">
            料头损耗率:{{ headLossRate }}
            </el-col>
            <el-col :span="20">
              计算公式：如何单位用量为空 结果为空 如果不为空 结果为"1%"
            </el-col>
            </el-row>

          <el-row :gutter="20">
            <el-col :span="4">
            辅材费用:{{ auxiliaryCost }}
            </el-col>
            <el-col :span="20">
              计算公式：=IF(E3="","",0) 如果单位用量为空 结果为空否则为0
            </el-col>
          </el-row>

          
          <el-row :gutter="20">
            <el-col :span="4">
            材料不良费: {{ materialDefectFee }}
            </el-col>
            <el-col :span="20">
              <!-- 计算公式：   return (data.form.unitPrice/1000*(data.form.netWeight+data.form.materialHeadWeight/data.form.cavitiesNumber)*(1-data.form.inferiorMaterial)
            -data.form.wasteMaterialPrice/1000*(data.form.netWeight+data.form.materialHeadWeight/data.form.cavitiesNumber)*(1-data.form.headLossRate)*(1-data.form.inferiorMaterial)+data.form.auxiliaryCost)*data.form.materialDefectRate
            -->
            计算公式："如果模穴数不为空(材料单价{{data.form.unitPrice}}/1000*（净重{{data.form.netWeight}}+料头重 {{data.form.materialHeadWeight}} /模穴数{{ data.form.cavitiesNumber }}*(1-次料{{ data.form.inferiorMaterial }}）-废料单价{{ data.form.wasteMaterialPrice }}/1000*(净重{{ data.form.netWeight }}
              +料头重{{ data.form.materialHeadWeight }} / 模穴数 {{ data.form.cavitiesNumber }})*(1-料头损耗率{{ data.form.headLossRate }})*(1-次料{{ data.form.inferiorMaterial }})+辅材费用{{ auxiliaryCost }})*材料不良率{{ data.form.materialDefectRate }} 如果模穴数为空 结果为空"
            <!-- 计算公式： "如果模穴数不为空 (材料单价/1000*(净重+料头重/模穴数)*(1-次料)-废料单价/1000*(净重+料头重/模穴数)*(1-料头损耗率)*(1-次料)+辅材费用)*材料不良率 如果模穴数为空 结果为空" -->

            </el-col>
          </el-row>

          <el-row :gutter="20">
            <el-col :span="4">
            材料成本: {{ materialCost }}
            </el-col>
            <el-col :span="20">
              计算公式：如果模穴数不为空 (材料单价{{data.form.unitPrice}}/1000*(净重{{data.form.netWeight}}+料头重{{data.form.materialHeadWeight}}/模穴数{{ data.form.cavitiesNumber }})*(1+材料损耗率{{ data.form.materialWastageRate }})*(1-次料{{ data.form.inferiorMaterial }})-废料单价{{data.form.wasteMaterialPrice}}/1000*料头重{{data.form.materialHeadWeight}}/模穴数{{data.form.cavitiesNumber}}*(1-料头损耗率{{ data.form.headLossRate }})*(1-次料{{ data.form.inferiorMaterial }})+辅材费用{{ data.form.auxiliaryCost }})+材料不良费{{data.form.materialDefectFee}}+注塑其他{{data.form.moldInjectionManagementRate }} 如果模穴数为空 结果为" "
              <!-- //        return (data.form.unitPrice/1000*(data.form.netWeight+data.form.materialHeadWeight/data.form.cavitiesNumber)*(1+data.form.materialWastageRate)*(1-data.form.inferiorMaterial)
      //        -data.form.wasteMaterialPrice/1000*data.form.materialHeadWeight/data.form.cavitiesNumber*(1-data.form.headLossRate)*(1-data.form.inferiorMaterial)+data.form.auxiliaryCost)+data.form.materialDefectFee+data.form.moldInjectionManagementRate -->
            
            </el-col>
            </el-row>
                <el-row :gutter="20">
            <el-col :span="4">
            材料管理费: {{ materialManagementFee }}
            </el-col>
            <el-col :span="20">
              计算公式：如果材料成本不为空  材料成本*材料管理费占比   如果材料成本为空 结果为" "
            </el-col> 
            </el-row>
                <el-row :gutter="20">
            <el-col :span="4">
            材料利润: {{ materialProfit }}
            </el-col>
            <el-col :span="20">
              计算公式：  如果材料成本不为空  (材料成本+材料管理费)*材料利润占比   如果材料成本为空 结果为" "     
            </el-col>
            </el-row>

            <el-row :gutter="20">
            <el-col :span="4">
            材料成本合计: {{ materialTotalCost }}
            </el-col>
            <el-col :span="20">
              计算公式：如果材料成本不为空  (材料成本+材料管理费+材料利润)*单位用量   如果材料成本为空 结果为" "    
            </el-col>
            </el-row>
            <!--模具相关计算-->


            <!-- 模具维修费用/pcs	模具加工不良费用	模具注塑成本	-->
            <el-row :gutter="20">
            <el-col :span="4">
            模具维修费用/pcs: {{ moldFixCostPcs }}
            </el-col>
            <el-col :span="20">
              计算公式：   模具维修费用/(模具维修天数*22*3600*模穴数/周期*效率) 
            </el-col>
            </el-row>

            <el-row :gutter="20">
            <el-col :span="4">
            模具加工不良费用: {{ moldDefectCost }}
            </el-col>
            <el-col :span="20">
              计算公式：(成本率/(模穴数/周期*秒/时*效率)+模具维修费用/pcs+模具维修其他费用)*模具工时不良率 =(AB3/(K3/AC3*AD3*AE3)+AM3+AH3)*AI3
            </el-col>
            </el-row>


            <el-row :gutter="20">
            <el-col :span="4">
            模具注塑成本: {{ moldInjectionCost }}
            </el-col>
            <el-col :span="20">
              计算公式：成本率/(模穴数/周期*秒/时*效率)+模具维修费用/pcs+模具加工不良费用+模具维修其他费用 =AB2/(K2/AC2*AD2*AE2)+AM2+AN2+AH2
            </el-col>
            </el-row>
            <!-- 模具注塑管理费	模具利润	注塑成本合计 -->

            <el-row :gutter="20">
            <el-col :span="4">
            模具注塑管理费: {{ moldInjectionManagementCost }}
            </el-col>
            <el-col :span="20">
              计算公式：模具注塑成本*模具注塑管理费占比    =AO2*AK2 
            </el-col>
            </el-row>

            <el-row :gutter="20">
            <el-col :span="4">
            模具利润: {{ moldProfit }}
            </el-col>
            <el-col :span="20">
              计算公式： (模具注塑成本+模具注塑管理费)*材料管理费          =IF(AO3="","",(AO3+AP3)*W3)  
            </el-col>
            </el-row>

            <el-row :gutter="20">
            <el-col :span="4">
            注塑成本合计: {{ moldTotalCost }}
            </el-col>
            <el-col :span="20">
              计算公式：(模具注塑成本+模具注塑管理费+模具利润)*单位用量  =(AO2+AP2+AQ2)*E2 
            </el-col>
            </el-row>
          <!-- 工时	人工费	总成本	产能（Kpcs/D） -->
          <el-row :gutter="20">
            <el-col :span="4">
            工时: {{ laborHours }}
            </el-col>
            <el-col :span="20">
              计算公式： 周期/模穴数 =AC2/K2 
            </el-col>
            </el-row>

            <el-row :gutter="20">
            <el-col :span="4">
            人工费: {{ laborCost }}
            </el-col>
            <el-col :span="20">
              计算公式：注塑工程师人力{{data.form.injectionEngineerCount}}*注塑工程师工费率{{data.form.injectionEngineerRate}}/3600*工时{{laborHours}}*单位用量{{ data.form.unitDosage }}    =AT3*AU3/3600*AV3*E3
          </el-col>
            </el-row>
            <el-row :gutter="20">
            <el-col :span="4">
            总成本: {{ totalCost }}
            </el-col>
            <el-col :span="20">
              计算公式：材料成本合计+注塑成本合计+人工费 =Y2+AR2+AW2
            </el-col>
            </el-row>

            <el-row :gutter="20">
            <el-col :span="4">
            产能（Kpcs/D）: {{ capacityKpcsPerDay }}
            </el-col>
            <el-col :span="20">
              计算公式：22*秒/时{{data.form.periodUnit}}*模穴数{{data.form.cavitiesNumber}}/周期{{data.form.period}}*效率{{data.form.efficiency}}/1000*(1-材料不良率{{ data.form.materialDefectRate }})   =22*AD3*K3/AC3*AE3/1000*(1-M3)
            </el-col>
            </el-row>
    </div>

        <div style="text-align: right;">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </div>
   </el-dialog>
</div>
  <div class="rightStyle">
      
    </div>
    </div>
  </div>


</template>

<script setup name="Molding">
import { listMolding, getMolding, delMolding, addMolding, updateMolding } from "@/api/system/molding"
import { ref } from "vue"
const { proxy } = getCurrentInstance()
const emit = defineEmits(['changeVal'])
const moldingList = ref([])
const moldingsum = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    pid: null,
  },
  rules: {
    pid: [
      { required: true, message: "产品ID不能为空", trigger: "blur" }
    ],
    ptype: [
      { required: true, message: "产品类型不能为空", trigger: "change" }
    ],
    unitDosage: [
      { required: true, message: "单位用量不能为空", trigger: "blur" }
    ],
    unitPrice: [
      { required: true, message: "材料单价不能为空", trigger: "blur" }
    ],
  }
})
// const sumColumns = ['materialTotalCost','moldTotalCost','laborCost']
// const getSummaries = ({ columns, data }) => {
// const sums = []
  
//   columns.forEach((column, index) => {
//     // First column: show "合计"
//     if (index === 0) {
//       sums[index] = '合计'
//       return
//     }

//     // Check if this column should be summed
//     if (sumColumns.includes(column.property)) {
//       const values = data.map(item => Number(item[column.property]))
      
//       // Only sum if all values are valid numbers
//       if (!values.every(value => isNaN(value))) {
//         const sum = values.reduce((prev, curr) => {
//           const value = Number(curr)
//           return !isNaN(value) ? prev + curr : prev
//         }, 0)
        
//         // Format with currency for price/total
//         if (column.property === 'price' || column.property === 'total') {
//           sums[index] = `¥${sum.toFixed(2)}`
//         } else {
//           sums[index] = sum
//         }
//       } else {
//         sums[index] = ''
//       }
//     } else {
//       // Non-summed columns: show dash
//       sums[index] = ''
//     }
//   })
//   emit('changeVal',sums[15])
//   return sums
// }

const handleAddRow = () => {
    moldingList.value.push({
      isEditing: true,
      isAdd: true,
    })
}

// const handleDeleteRow = (index) => {
//   moldingList.value.splice(index, 1)
// }



const originalData = ref([]) // 用于存储原始数据，用于取消操作
const startEdit = (index) => {
  // 保存原始数据
  originalData.value[index] = { ...moldingList.value[index] }
  moldingList.value[index].isEditing = true
}


//---------------------**********计算总成本***********------------------------------

//---------------------**********计算材料成本合计开始***********------------------------------
//计算材料成本合计
function materialCostSum(currentRow) { 
//材料成本
  const materialCost = materialCostComputer(currentRow)
  if(!materialCost){
        return ""
    }
//材料管理费     材料成本*材料管理费占比
  const materialManageCost = materialCost*Number(currentRow.materialManagementRate ?? 0)/100;
//材料利润   (材料成本+材料管理费)*材料利润占比 
  const materialProfit = (materialCost+materialManageCost)*Number(currentRow.materialProfitRate ?? 0)/100;
//材料成本合计
  return materialCost+materialManageCost+materialManageCost;
}
//材料成本
//计算公式：如果模穴数不为空 (材料单价/1000*(净重+料头重/模穴数)*(1+材料损耗率)*(1-次料)-废料单价/1000*料头重/模穴数*(1-料头损耗率)*(1-次料)+辅材费用)+材料不良费+注塑其他
function materialCostComputer(currentRow) { 
  // const form = data.form;
   const unitPrice = Number(currentRow.unitPrice ?? 0) / 1000;  //材料单价
  const wastePrice = Number(currentRow.wasteMaterialPrice ?? 0) / 1000;  //废料单价
  const auxiliaryCost = Number(currentRow.auxiliaryCost ?? 0);  // 辅材费用
  const defectFee = Number(currentRow.materialDefectFee ?? 0); //材料不良费

  
  const netWeight = Number(currentRow.netWeight ?? 0);  // 净重
  const headWeight = Number(currentRow.materialHeadWeight ?? 0); // 料头重
  const cavities = Number(currentRow.cavitiesNumber ?? 1) || 1; // 防除零  模穴数
  
  const wastageRate = Number(currentRow.materialWastageRate ?? 0)/100;  //材料损耗率
  const inferiorRate = Number(currentRow.inferiorMaterial ?? 0)/100;  // 次料
  const headLossRate = Number(currentRow.headLossRate ?? 0)/100;  //料头损耗率
  const injectionMoldingOther = Number(currentRow.injectionMoldingOther ?? 0);  //注塑其他
  

  // 第二层：提取高频子表达式（核心优化）
  const headWeightPerCavity = headWeight / cavities;  // 公共：料头重量分摊
  const qualityFactor = 1 - inferiorRate;             // 次料
  const headLossFactor = 1 - headLossRate;            // 公共：料头损耗率

  // 第三层：计算主要组成部分
  const baseWeight = netWeight + headWeightPerCavity;   // 基础重量
  
  // 主材料成本部分
  const mainPart = unitPrice * baseWeight * (1 + wastageRate) * qualityFactor;
  
  // 废料抵扣部分
  const wastePart = wastePrice * headWeightPerCavity * headLossFactor * qualityFactor;
  
  // 第四层：汇总计算
  const subTotal = mainPart - wastePart + auxiliaryCost; // 前段合计
  //const finalResult = subTotal + defectFee + manageRate; // 最终结果
  const finalResult = subTotal + defectFee + injectionMoldingOther; // 最终结果

   return finalResult;
}
//---------------------**********计算注塑成本合计***********------------------------------

 //注塑成本合计
function moldingCostSum(currentRow) { 

   //模具注塑成本 
   const moldingCost = moldInjectionCostComputer(currentRow);
   if(!moldingCost){
        return ""
    }
    //模具注塑管理费  计算公式 模具注塑成本*模具注塑管理费占比
    const moldInjectionManagementCost = moldingCost*Number(currentRow.moldInjectionManagementRate ?? 0)/100;
    //模具利润    计算公式 (模具注塑成本+模具注塑管理费)*模具注塑利润占比
    const moldProfit = (moldingCost+moldInjectionManagementCost)*Number(currentRow.moldInjectionProfitRate ?? 0)/100;

   //注塑成本合计 计算公式：(模具注塑成本+模具注塑管理费+模具利润)*单位用量  =(AO2+AP2+AQ2)*E2 
     const unitDosage = Number(currentRow.unitDosage ?? 0);
     const moldingTotalCost = (moldingCost+moldInjectionManagementCost+moldProfit)*unitDosage
  return moldingTotalCost;
}

//模具注塑成本      计算公式：成本率/(模穴数/周期*秒/时*效率)+模具维修费用/pcs+模具加工不良费用+模具维修其他费用 =AB2/(K2/AC2*AD2*AE2)+AM2+AN2+AH2
function moldInjectionCostComputer(currentRow) { 
  const costRate = Number(currentRow.costRate ?? 0); // 成本率
  const cavitiesNumber = Number(currentRow.cavitiesNumber ?? 1); // 模穴数
  const period = Number(currentRow.period ?? 1);  // 周期时间
  //const periodUnit = Number(currentRow.periodUnit ?? 1); // 周期单位
  const periodUnit = 3600; // 周期单位
  const efficiency = Number(currentRow.efficiency ?? 1)/100;  // 效率
  const moldFixCostPcs = Number(moldFixCostPcsComputer(currentRow) ?? 0); // 模具维修费用/pcs

  const moldFixOtherCost = Number(currentRow.moldFixOtherCost ?? 0);  // 模具维修其他费用
  const moldDefectCost = Number(currentRow.moldDefectCost ?? 0); // 模具加工不良费用

 // 2. 严格除零保护（所有乘积因子必须>0）
  if (cavitiesNumber <= 0) {
    console.warn('模穴数必须大于0');
    return 0;
  }
  if (period <= 0) {
    console.warn('周期时间必须大于0');
    return 0;
  }
  if (periodUnit <= 0) {
    console.warn('周期单位必须大于0');
    return 0;
  }
  if (efficiency < 0) {
    console.warn('效率必须大于等于0');
    return 0;
  }

  // 3. 提取公共表达式：计算单位时间产能
  // 单位产能 = (模穴数 / 单件周期) × 周期单位 × 效率
  const capacityPerUnit = (cavitiesNumber / period) * periodUnit * efficiency;


  if (capacityPerUnit === 0) {
    console.warn('单位产能计算结果为零');
    return 0;
  }

  // 4. 分步计算（提高可读性）
  const costRatePerPcs = costRate / capacityPerUnit;  // 费率分摊
  const additionalCost = moldFixCostPcs + moldDefectCost + moldFixOtherCost; // 附加成本
 // 5. 汇总结果
  const result = costRatePerPcs + additionalCost;
  return result
}




//模具维修费用pcs     计算公式：   模具维修费用/(模具维修天数*22*3600*模穴数/周期*效率) 
// const moldFixCostPcs = computed(
//   () => {
//       return data.form.moldFixCost/(data.form.moldFixDays*22*3600*data.form.cavitiesNumber/data.form.period*data.form.efficiency)
//   }
// )
function moldFixCostPcsComputer(currentRow){ 
  // 1. 安全提取并转换所有变量
  // const moldFixCost = Number(currentRow.moldFixCost ?? 0); 
  // const moldFixDays = Number(currentRow.moldFixDays ?? 0);
  
  const moldFixCost = 250; 
  const moldFixDays = 3;
  const cavitiesNumber = Number(currentRow.cavitiesNumber ?? 1);
  const period = Number(currentRow.period ?? 1);        // 生产周期（秒）
  const efficiency = Number(currentRow.efficiency ?? 1); // 效率系数
  // 2. 除零保护（关键！）
  if (cavitiesNumber <= 0 || period <= 0 || efficiency <= 0) {
    console.warn('计算参数不能为零或负数', { cavitiesNumber, period, efficiency });
    return 0; // 或返回 null/NaN 表示无效
  }
  
  // 3. 分步计算分母（明确运算顺序）
  const dailySeconds = 22 * 3600;                // 每天工作秒数（22小时）
  const totalSeconds = moldFixDays * dailySeconds; // 总可用时间
  const cavitiesPerPeriod = cavitiesNumber / period; // 每秒产能
  const effectiveCapacity = cavitiesPerPeriod * efficiency; // 有效产能
  
  const denominator = totalSeconds * effectiveCapacity;
  
  // 4. 最终计算
  if (denominator === 0) return 0;
  const result = moldFixCost / denominator;
  currentRow.moldFixCostPcs = Number(result.toFixed(6))
// 5. 精度处理（成本通常保留6位小数）
  return Number(result.toFixed(6));
};


//模具加工不良费用  (成本率/(模穴数/周期*秒/时*效率)+模具维修费用/pcs+模具维修其他费用)*模具工时不良率 =(AB3/(K3/AC3*AD3*AE3)+AM3+AH3)*AI3
// const moldDefectCost = computed(
//   () => {
//       return (data.form.costRate/(data.form.cavitiesNumber/data.form.period*data.form.periodUnit*data.form.efficiency)+data.form.moldFixCostPcs+data.form.moldFixOtherCost)*data.form.moldDefectRate
//   }
// )


function moldDefectCostComputer(currentRow){
 // 1. 安全提取并转换所有变量
  const costRate = Number(currentRow.costRate ?? 0);
  const cavitiesNumber = Number(currentRow.cavitiesNumber ?? 1);
  const period = Number(currentRow.period ?? 1);
 // const periodUnit = Number(form.periodUnit ?? 1);
  const periodUnit = 3600
  const efficiency = Number(currentRow.efficiency ?? 1);
  const moldFixCostPcs = Number(currentRow.moldFixCostPcs ?? 0);
  const moldFixOtherCost = Number(currentRow.moldFixOtherCost ?? 0);
  //const moldDefectRate = Number(currentRow.moldDefectRate ?? 0);
   const  moldDefectRate = 0.020
  // 2. 严格除零保护（所有乘积分母因子必须>0）
  if (cavitiesNumber <= 0) {
    console.warn('模穴数必须大于0');
    return 0;
  }
  if (period <= 0) {
    console.warn('周期时间必须大于0');
    return 0;
  }
  if (periodUnit <= 0) {
    console.warn('周期单位必须大于0');
    return 0;
  }
  if (efficiency <= 0) {
    console.warn('效率必须大于0');
    return 0;
  }

  // 3. 分步计算（提取公共表达式）
  // 单位时间产能 = (模穴数 / 单件周期) × 周期单位 × 效率
  const capacityPerUnit = (cavitiesNumber / period) * periodUnit * efficiency;
  
  // 除数不能为零
  if (capacityPerUnit === 0) {
    console.warn('单位时间产能计算为零');
    return 0;
  }

  // 4. 计算基础成本（costRate ÷ 产能 + 单件成本 + 其他成本）
  const baseCost = (costRate / capacityPerUnit) + moldFixCostPcs + moldFixOtherCost;
  
  // 5. 应用缺陷率调整
  const result = baseCost * moldDefectRate;
  currentRow.moldDefectCost = result
};



//人工费: 计算公式：注塑工程师人力*注塑工程师工费率/3600*工时*单位用量
function laborCostSum(currentRow){
      const engineerCount = Number(currentRow.injectionEngineerCount ?? 0); //注塑工程师人力
      const engineerRate = Number(currentRow.injectionEngineerRate ?? 0);   //注塑工程师工费率
      const period = Number(currentRow.period ?? 0);
      const cavitiesNumber = Number(currentRow.cavitiesNumber ?? 1);
      const unitDosage = Number(currentRow.unitDosage ?? 0); //单位用量
      //计算工时
      const costPerSecond = engineerCount * engineerRate ;
      const laborHours = period / cavitiesNumber;
      //计算人工费
      const laborCos = costPerSecond/3600*laborHours*unitDosage
      return laborCos
}





//材料成本合计+注塑成本合计+人工费
// function totalCostSum(currentRow) { 
// let materialCost = materialCostSum(currentRow)
// materialCost = Number(Number(materialCost??0).toFixed(6))
// console.log("materialCost")
// console.log(materialCost)
// let moldingCost = moldingCostSum(currentRow)
// moldingCost = Number(Number(moldingCost??0).toFixed(6))
// console.log("moldingCost")
// console.log(moldingCost)
// let laborCost = laborCostSum(currentRow)
// laborCost = Number(Number(laborCost??0).toFixed(6))
// console.log("laborCost")
// console.log(laborCost)
// return (materialCost+ moldingCost + laborCost).toFixed(6);
// }

const saveEdit = (index) => {
  moldingList.value[index].isEditing = false
  //moldingList.value[index]

          let materialTotalCost =  materialCostSum(moldingList.value[index])
          moldingList.value[index].materialTotalCost = materialTotalCost
   
         
          let moldingTotalCost =  moldingCostSum(moldingList.value[index])
          moldingList.value[index].moldTotalCost = moldingTotalCost
        
          let laborCost = laborCostSum(moldingList.value[index])
          moldingList.value[index].laborCost = laborCost
         

         materialTotalCost =   Number(materialTotalCost??0)
         moldingTotalCost = Number(moldingTotalCost??0)
         laborCost = Number(laborCost??0)

         const totalCost = Number(materialTotalCost+moldingTotalCost+laborCost).toFixed(6);
         moldingList.value[index].totalCost = totalCost
       

if(moldingList.value[index].isAdd){
      moldingList.value[index].isAdd=false
    addMolding(moldingList.value[index]).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
   }else{
      //materialTotalCost
      //const totalCost = totalCostSum(moldingList.value[index]);
          updateMolding(moldingList.value[index]).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
    })
     emit('changeVal',totalCost)
}
  // 这里调用API保存数据
 

}
const cancelEdit = (index) => {
  // 恢复原始数据
  moldingList.value[index] = { ...originalData.value[index] }
  moldingList.value[index].isEditing = false
  getList()
}


//耗料 计算公式：如果模穴数不空 (净重+料头重/模穴数)*(1+材料损耗率+材料不良率)*(1-次料)  如果模穴数为空 结果为“ ”
const consumerMaterial = computed(() => {

   if(data.form.cavitiesNumber == ""){
      return ""
   }
    const form = data.form;
    const netWeight = Number(form.netWeight ?? 0);
    const headWeight = Number(form.materialHeadWeight ?? 0);
    const cavities = Number(form.cavitiesNumber ?? 1) || 1; // 防止0
    const wastage = Number(form.materialWastageRate ?? 0);
    const defect = Number(form.materialDefectRate ?? 0);
    const inferior = Number(form.inferiorMaterial ?? 0);
  //  return (data.form.netWeight+data.form.materialHeadWeight/data.form.cavitiesNumber)*(1+data.form.materialWastageRate+data.form.materialDefectRate)*(1-data.form.inferiorMaterial)
  return Number(
    ((netWeight + headWeight / cavities) * 
     (1 + wastage + defect) * 
     (1 - inferior)).toFixed(4)
  );
})
watchEffect(() => {
  data.form.consumerMaterial = consumerMaterial.value
});

//料头损耗率 计算公式 如何单位用量为空 结果为空 如果不为空 结果为"%"
const headLossRate = computed(
   ()=>data.form.unitDosage=="" || data.form.unitDosage==null?"":"1"
)

//辅材费用 计算公式：=IF(E3="","",0) 如果单位用量为空 结果为空否则为0
const auxiliaryCost = computed(() => {
     return data.form.unitDosage=="" || data.form.unitDosage==null?"":0
})

watchEffect(() => {
  data.form.headLossRate = headLossRate.value
  data.form.auxiliaryCost = auxiliaryCost.value
});


//材料不良费 计算公式： 如果模穴数不为空 (材料单价/1000*(净重+料头重/模穴数)*(1-次料)-废料单价/1000*(净重+料头重/模穴数)*(1-料头损耗率)*(1-次料)+辅材费用)*材料不良率 如果模穴数为空 结果为" "
// const materialDefectFee = computed(
//   () => {
//     if(data.form.cavitiesNumber == ""){
//         return ""
//     }
//        return (data.form.unitPrice/1000*(data.form.netWeight+data.form.materialHeadWeight/data.form.cavitiesNumber)*(1-data.form.headLossRate)
//        -data.form.wasteMaterialPrice/1000*(data.form.netWeight+data.form.materialHeadWeight/data.form.cavitiesNumber)*(1-data.form.headLossRate)*(1-data.form.inferiorMaterial)+data.form.auxiliaryCost)*data.form.materialDefectRate
//     }
// )

const materialDefectFee = computed(() => {
    if(data.form.cavitiesNumber == ""){
        return ""
    }
  const form = data.form || {};
  
  // 1. 安全转换所有输入值（提取公共变量）
  const unitPrice = Number(form.unitPrice ?? 0) / 1000;
  const wastePrice = Number(form.wasteMaterialPrice ?? 0) / 1000;
  const auxiliaryCost = Number(form.auxiliaryCost ?? 0);
  
  const netWeight = Number(form.netWeight ?? 0);
  const headWeight = Number(form.materialHeadWeight ?? 0);
  const cavities = Number(form.cavitiesNumber ?? 1) || 1; // 防除零
  const headLossRate = Number(form.headLossRate ?? 0);
  const inferiorRate = Number(form.inferiorMaterial ?? 0);
  const defectRate = Number(form.materialDefectRate ?? 0);

  // 2. 提取公共子表达式（关键优化点）
  const baseWeight = netWeight + headWeight / cavities;
  const afterHeadLoss = baseWeight * (1 - headLossRate);
  
  // 3. 分步计算（公式对应原式）
  const mainCost = unitPrice * afterHeadLoss;
  const wasteDeduction = wastePrice * afterHeadLoss * (1 - inferiorRate);
  const subTotal = mainCost - wasteDeduction + auxiliaryCost;
  
  // 4. 最终结果
  const result = subTotal * defectRate;
  
  // 5. 处理精度，保留4位小数
  return Number(result.toFixed(4));
});

watchEffect(() => {
data.form.materialDefectFee = materialDefectFee.value
});
// 材料成本 计算公式：  计算公式：如果模穴数不为空 (材料单价/1000*(净重+料头重/模穴数)*(1+材料损耗率)*(1-次料)-废料单价/1000*料头重/模穴数*(1-料头损耗率)*(1-次料)+辅材费用)+材料不良费+注塑其他 如果模穴数为空 结果为" ""
// const materialTotalCost = computed(
//   () => {
//     if(data.form.cavitiesNumber == ""){
//         return ""
//     }
//        return (data.form.unitPrice/1000*(data.form.netWeight+data.form.materialHeadWeight/data.form.cavitiesNumber)*(1+data.form.materialWastageRate)*(1-data.form.inferiorMaterial)
//        -data.form.wasteMaterialPrice/1000*data.form.materialHeadWeight/data.form.cavitiesNumber*(1-data.form.headLossRate)*(1-data.form.inferiorMaterial)+data.form.auxiliaryCost)+data.form.materialDefectFee+data.form.moldInjectionManagementRate
//   }
// )
const materialCost = computed(() => {
   if(data.form.cavitiesNumber == ""){
        return ""
    }
  const form = data.form || {};
  
  // 第一层：安全转换所有原始数据（提取公共系数）
  const unitPrice = Number(form.unitPrice ?? 0) / 1000;
  const wastePrice = Number(form.wasteMaterialPrice ?? 0) / 1000;
  const auxiliaryCost = Number(form.auxiliaryCost ?? 0);
  const defectFee = Number(form.materialDefectFee ?? 0);
  const manageRate = Number(form.moldInjectionManagementRate ?? 0);
  
  const netWeight = Number(form.netWeight ?? 0);
  const headWeight = Number(form.materialHeadWeight ?? 0);
  const cavities = Number(form.cavitiesNumber ?? 1) || 1; // 防除零
  
  const wastageRate = Number(form.materialWastageRate ?? 0);
  const inferiorRate = Number(form.inferiorMaterial ?? 0);
  const headLossRate = Number(form.headLossRate ?? 0);

  // 第二层：提取高频子表达式（核心优化）
  const headWeightPerCavity = headWeight / cavities;  // 公共：料头重量分摊
  const qualityFactor = 1 - inferiorRate;             // 公共：劣质材料系数
  const headLossFactor = 1 - headLossRate;            // 公共：料损系数

  // 第三层：计算主要组成部分
  const baseWeight = netWeight + headWeightPerCavity;   // 基础重量
  
  // 主材料成本部分
  const mainPart = unitPrice * baseWeight * (1 + wastageRate) * qualityFactor;
  
  // 废料抵扣部分
  const wastePart = wastePrice * headWeightPerCavity * headLossFactor * qualityFactor;
  
  // 第四层：汇总计算
  const subTotal = mainPart - wastePart + auxiliaryCost; // 前段合计
  const finalResult = subTotal + defectFee + manageRate; // 最终结果

  // 第五层：精度处理
  return Number(finalResult.toFixed(4));
});
watchEffect(() => {
   data.form.materialCost = materialCost.value
});


//材料管理费 计算公式：如果材料成本不为空  材料成本*材料管理费占比   如果材料成本为空 结果为" "
const materialManagementFee = computed(
  () => {
    if(data.form.materialCost == ""){
        return ""
    }
  const form = data.form || {};
  const materialCost = Number(form.materialCost ?? 0);
  const materialManagementRate = Number(form.materialManagementRate ?? 0);
   return materialCost.value*materialManagementRate
  }
)
watchEffect(() => {
   data.form.materialManagementFee = materialManagementFee.value
});

//材料利润   计算公式：  如果材料成本不为空  (材料成本+材料管理费)*材料利润占比   如果材料成本为空 结果为" "     
const materialProfit = computed(
  () => {
    if(data.form.materialCost == ""){
        return ""
    }
  const form = data.form || {};
  const materialProfitRate = Number(form.materialProfitRate ?? 0);
   return (materialCost.value??0+materialManagementFee.value??0)*form.materialManagementRate
  }
)
watchEffect(() => {
  data.form.materialProfit = materialProfit.value;
});
//材料成本合计 材料成本+材料管理费+材料利润

const materialTotalcost = computed(() => {
   return materialCost.value + materialManagementFee.value + materialProfit.value
  })
watchEffect(() => {
  data.form.materialTotalcost = materialTotalcost.value;
});


//模具维修费用pcs     计算公式：   模具维修费用/(模具维修天数*22*3600*模穴数/周期*效率) 
// const moldFixCostPcs = computed(
//   () => {
//       return data.form.moldFixCost/(data.form.moldFixDays*22*3600*data.form.cavitiesNumber/data.form.period*data.form.efficiency)
//   }
// )
const moldFixCostPcs = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换所有变量
  const moldFixCost = Number(form.moldFixCost ?? 0);
  const moldFixDays = Number(form.moldFixDays ?? 0);
  
  const cavitiesNumber = Number(form.cavitiesNumber ?? 1);
  const period = Number(form.period ?? 1);        // 生产周期（秒）
  const efficiency = Number(form.efficiency ?? 1); // 效率系数
  
  // 2. 除零保护（关键！）
  if (cavitiesNumber <= 0 || period <= 0 || efficiency <= 0) {
    console.warn('计算参数不能为零或负数', { cavitiesNumber, period, efficiency });
    return 0; // 或返回 null/NaN 表示无效
  }
  
  // 3. 分步计算分母（明确运算顺序）
  const dailySeconds = 22 * 3600;                // 每天工作秒数（22小时）
  const totalSeconds = moldFixDays * dailySeconds; // 总可用时间
  const cavitiesPerPeriod = cavitiesNumber / period; // 每秒产能
  const effectiveCapacity = cavitiesPerPeriod * efficiency; // 有效产能
  
  const denominator = totalSeconds * effectiveCapacity;
  
  // 4. 最终计算
  if (denominator === 0) return 0;
  
  const result = moldFixCost / denominator;
  
  // 5. 精度处理（成本通常保留6位小数）
  return Number(result.toFixed(6));
});
watchEffect(() => {
  data.form.moldFixCostPcs = moldFixCostPcs.value;
});


//模具加工不良费用  (成本率/(模穴数/周期*秒/时*效率)+模具维修费用/pcs+模具维修其他费用)*模具工时不良率 =(AB3/(K3/AC3*AD3*AE3)+AM3+AH3)*AI3
// const moldDefectCost = computed(
//   () => {
//       return (data.form.costRate/(data.form.cavitiesNumber/data.form.period*data.form.periodUnit*data.form.efficiency)+data.form.moldFixCostPcs+data.form.moldFixOtherCost)*data.form.moldDefectRate
//   }
// )


const moldDefectCost = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换所有变量
  const costRate = Number(form.costRate ?? 0);
  const cavitiesNumber = Number(form.cavitiesNumber ?? 1);
  const period = Number(form.period ?? 1);
  const periodUnit = Number(form.periodUnit ?? 1);
  const efficiency = Number(form.efficiency ?? 1);
  const moldFixCostPcs = Number(form.moldFixCostPcs ?? 0);
  const moldFixOtherCost = Number(form.moldFixOtherCost ?? 0);
  const moldDefectRate = Number(form.moldDefectRate ?? 0);

  // 2. 严格除零保护（所有乘积分母因子必须>0）
  if (cavitiesNumber <= 0) {
    console.warn('模穴数必须大于0');
    return 0;
  }
  if (period <= 0) {
    console.warn('周期时间必须大于0');
    return 0;
  }
  if (periodUnit <= 0) {
    console.warn('周期单位必须大于0');
    return 0;
  }
  if (efficiency <= 0) {
    console.warn('效率必须大于0');
    return 0;
  }

  // 3. 分步计算（提取公共表达式）
  // 单位时间产能 = (模穴数 / 单件周期) × 周期单位 × 效率
  const capacityPerUnit = (cavitiesNumber / period) * periodUnit * efficiency;
  
  // 除数不能为零
  if (capacityPerUnit === 0) {
    console.warn('单位时间产能计算为零');
    return 0;
  }

  // 4. 计算基础成本（costRate ÷ 产能 + 单件成本 + 其他成本）
  const baseCost = (costRate / capacityPerUnit) + moldFixCostPcs + moldFixOtherCost;
  
  // 5. 应用缺陷率调整
  const result = baseCost * moldDefectRate;

  // 6. 精度处理（成本保留4-6位小数）
  return Number(result.toFixed(4));
});


//模具注塑成本      计算公式：成本率/(模穴数/周期*秒/时*效率)+模具维修费用/pcs+模具加工不良费用+模具维修其他费用 =AB2/(K2/AC2*AD2*AE2)+AM2+AN2+AH2
// const moldInjectionCost = computed(
//   () => {
//       return data.form.costRate/(data.form.cavitiesNumber/data.form.period*data.form.periodUnit*data.form.efficiency)+data.form.moldFixCostPcs+data.form.efficiency+data.form.moldFixOtherCost
//   }
// )
watchEffect(() => {
  data.form.moldDefectCost = moldDefectCost.value;
});


const moldInjectionCost = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换所有变量（使用空值合并运算符）
  const costRate = Number(form.costRate ?? 0);
  const cavitiesNumber = Number(form.cavitiesNumber ?? 1);
  const period = Number(form.period ?? 1);
  const periodUnit = Number(form.periodUnit ?? 1);
  const efficiency = Number(form.efficiency ?? 1);
  const moldFixCostPcs = Number(form.moldFixCostPcs ?? 0);
  const moldFixOtherCost = Number(form.moldFixOtherCost ?? 0);

  // 2. 严格除零保护（所有乘积因子必须>0）
  if (cavitiesNumber <= 0) {
    console.warn('模穴数必须大于0');
    return 0;
  }
  if (period <= 0) {
    console.warn('周期时间必须大于0');
    return 0;
  }
  if (periodUnit <= 0) {
    console.warn('周期单位必须大于0');
    return 0;
  }
  if (efficiency <= 0) {
    console.warn('效率必须大于0');
    return 0;
  }

  // 3. 提取公共表达式：计算单位时间产能
  // 单位产能 = (模穴数 / 单件周期) × 周期单位 × 效率
  const capacityPerUnit = (cavitiesNumber / period) * periodUnit * efficiency;
  
  if (capacityPerUnit === 0) {
    console.warn('单位产能计算结果为零');
    return 0;
  }

  // 4. 分步计算（提高可读性）
  const costRatePerPcs = costRate / capacityPerUnit;  // 费率分摊
  const additionalCost = moldFixCostPcs + efficiency + moldFixOtherCost; // 附加成本
  
  // 5. 汇总结果
  const result = costRatePerPcs + additionalCost;

  // 6. 精度处理（成本保留4位小数）
  return Number(result.toFixed(4));
});

watchEffect(() => {
  data.form.moldInjectionCost = moldInjectionCost.value;
});

//模具注塑管理费    计算公式：模具注塑成本*模具注塑管理费占比
// const moldInjectionManagementCost = computed(
//   () => {
//       return data.form.moldInjectionCost*data.form.moldInjectionManagementCostRate
//   }
// )

const moldInjectionManagementCost = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换
  const moldInjectionCost = Number(form.moldInjectionCost ?? 0);
  const managementRate = Number(form.moldInjectionManagementCostRate ?? 0);

  // 2. 计算（无需除零检查，乘法安全）
  const result = moldInjectionCost * managementRate;

  // 3. 精度处理（管理费率成本保留4位小数）
  return Number(result.toFixed(4));
});
watchEffect(() => {
  data.form.moldInjectionManagementCost = moldInjectionManagementCost.value;
});

//模具利润          计算公式： (模具注塑成本+模具注塑管理费)*模具注塑利润占比=(AO2+AP2)*AL2
// const moldProfit = computed(
//   () => {
//       return (data.form.moldInjectionCost+data.form.moldInjectionManagementCost)*data.form.moldInjectionProfitRate
//   }
// )



const moldProfit = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换（空值合并运算符）
  const moldInjectionCost = Number(form.moldInjectionCost ?? 0);
  const managementCost = Number(form.moldInjectionManagementCost ?? 0);
  const profitRate = Number(form.moldInjectionProfitRate ?? 0);

  // 2. 计算总成本和利润
  const totalCost = moldInjectionCost + managementCost;
  const result = totalCost * profitRate;

  // 3. 精度处理（利润保留4位小数）
  return Number(result.toFixed(4));
});

watchEffect(() => {
  data.form.moldProfit = moldProfit.value;
});


//注塑成本合计      计算公式：(模具注塑成本+模具注塑管理费+模具利润)*单位用量  =(AO2+AP2+AQ2)*E2 
// const moldTotalCost = computed(
//   () => {
//       return (data.form.moldInjectionCost+data.form.moldInjectionManagementCost+data.form.moldProfit)*data.form.unitDosage
//   }
// )



const moldTotalCost = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换
  const moldInjectionCost = Number(form.moldInjectionCost ?? 0);
  const managementCost = Number(form.moldInjectionManagementCost ?? 0);
  const moldProfit = Number(form.moldProfit ?? 0);
  const unitDosage = Number(form.unitDosage ?? 0);

  // 2. 计算总成本
  const totalCost = moldInjectionCost + managementCost + moldProfit;
  
  // 3. 最终成本
  const result = totalCost * unitDosage;

  // 4. 精度处理（保留4位小数）
  return Number(result.toFixed(4));
});
watchEffect(() => {
  data.form.moldTotalCost = moldTotalCost.value;
});

//工时:   计算公式： 周期/模穴数 
// const laborHours = computed(
//   () => {
//       return data.form.period/data.form.cavitiesNumber
//   }
// )

const laborHours = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换
  const period = Number(form.period ?? 0);
  const cavitiesNumber = Number(form.cavitiesNumber ?? 1);

  // 2. 严格除零保护
  if (cavitiesNumber <= 0) {
    console.warn('模穴数必须大于0');
    return 0; // 或返回 Infinity / NaN 根据业务需求
  }

  // 3. 计算结果
  const result = period / cavitiesNumber;

  // 4. 精度处理（根据业务场景选择）
  return Number(result.toFixed(4)); // 保留4位小数
});



//人工费: 计算公式：注塑工程师人力*注塑工程师工费率/3600*工时*单位用量
// const laborCost = computed(
//   () => {
//       return data.form.injectionEngineerCount*data.form.injectionEngineerRate/3600*data.form.laborHours*data.form.unitDosage
//   }
// )

watchEffect(() => {
  data.form.laborHours = laborHours.value;
});

const laborCost = computed(() => {
  const form = data.form || {};
  // 1. 安全提取并转换所有变量
  const engineerCount = Number(form.injectionEngineerCount ?? 0);
  const engineerRate = Number(form.injectionEngineerRate ?? 0);
  // const laborHours = Number(form.laborHours ?? 0);
  const unitDosage = Number(form.unitDosage ?? 0);
  const costPerSecond = engineerCount * engineerRate ;
   return Number((costPerSecond/costPerSecond * laborHours.value * unitDosage).toFixed(4));
});


watchEffect(() => {
   data.form.laborCost = laborCost.value;
});
//总成本:  计算公式：材料成本合计+注塑成本合计+人工费

// const totalCost = computed(
//   () => {
//       return data.form.materialTotalCost+data.form.moldingCost+data.form.laborCost
//   }
// )
// import { computed } from 'vue';

const totalCost = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换所有变量
  const materialCost = Number(form.materialTotalCost ?? 0);
  const moldingCost = Number(form.moldingCost ?? 0);
  const laborCost = Number(form.laborCost ?? 0);

  // 2. 直接相加（纯加法无需除零检查）
  const result = materialCost + moldingCost + laborCost;

  // 3. 精度处理（总成本保留2位小数）
  return Number(result.toFixed(4));
});
watchEffect(() => {
    data.form.totalCost = totalCost.value;
});
//产能（Kpcs/D）22*秒/时*模穴数/周期*效率/1000*(1-材料不良率) 

// const capacityKpcsPerDay = computed(
//   () => {
//       return 22*data.form.periodUnit*data.form.cavitiesNumber/data.form.period*data.form.efficiency/(1000*(1-data.form.materialDefectRate))
//   }
// )

const capacityKpcsPerDay = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换
  const periodUnit = Number(form.periodUnit ?? 1);
  const cavitiesNumber = Number(form.cavitiesNumber ?? 1);
  const period = Number(form.period ?? 1);
  const efficiency = Number(form.efficiency ?? 1);
  const materialDefectRate = Number(form.materialDefectRate ?? 0);

  // 2. 严格除零保护
  if (period <= 0) {
    console.warn('周期时间必须大于0');
    return 0;
  }
  
  // 3. 计算良品率
  const goodRate = 1 - materialDefectRate;
  if (goodRate <= 0) {
    console.warn('良品率必须大于0');
    return 0;
  }
 const dailyWorkSeconds = 22 ; 
 const result = dailyWorkSeconds*periodUnit * cavitiesNumber / period * efficiency / 1000 * goodRate;
   // 4. 精度处理
  return Number(result.toFixed(4));
});

watchEffect(() => {
    data.form.capacityKpcsPerDay = capacityKpcsPerDay.value;
});
const { queryParams, form, rules } = toRefs(data)

// const sumColumns = ['materialTotalCost','moldTotalCost','laborCost']
/** 查询注塑件成本列表 */
function getList() {
  loading.value = true
  listMolding(queryParams.value).then(response => {
    moldingList.value = response.rows
    moldingsum.value = response.rows
    total.value = response.total
    loading.value = false
})
}


   const showMoldingCost = computed(() => 
      moldingList.value.reduce((sum1, item) => sum1 + (item.moldTotalCost || 0), 0)
    ) 
   const showLaborCost = computed(() => 
      moldingList.value.reduce((sum, item) => sum + (item.laborCost || 0), 0)
    )
   const showMaterialTotalCost = computed(() => 
      moldingList.value.reduce((sum2, item) => sum2 + (item.materialTotalCost || 0), 0)
    ) 
    const showTotalCost = computed(() => showLaborCost.value + showMoldingCost.value + showMaterialTotalCost.value)




// 取消按钮
function cancel() {
  open.value = false
  reset()
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    pid: null,
    ptype: null,
    partNumber: null,
    partName: null,
    material: null,
    unitDosage: null,
    unitPrice: null,
    netWeight: null,
    materialHeadWeight: null,
    inferiorMaterial: null,
    wasteMaterialPrice: null,
    cavitiesNumber: null,
    materialWastageRate: null,
    materialDefectRate: null,
    materialOtherExpenses: null,
    materialManagementRate: null,
    materialProfitRate: null,
    injectionMoldingOther: null,
    materialConsumer: null,
    headLossRate: null,
    auxiliaryCost: null,
    materialDefectFee: null,
    materialCost: null,
    materialManagementFee: null,
    materialProfit: null,
    materialTotalCost: null,
    machineModel: null,
    moldType: null,
    costRate: null,
    period: null,
    periodUnit: null,
    efficiency: null,
    moldFixDays: null,
    moldFixCost: null,
    moldFixOtherCost: null,
    moldDefectRate: null,
    moldInjectionOtherCost: null,
    moldInjectionManagementRate: null,
    moldInjectionProfitRate: null,
    moldFixCostPcs: null,
    moldDefectCost: null,
    moldInjectionCost: null,
    moldInjectionManagementCost: null,
    moldProfit: null,
    moldTotalCost: null,
    workstation: null,
    injectionEngineerCount: null,
    injectionEngineerRate: null,
    laborHours: null,
    laborCost: null,
    totalCost: null,
    capacityKpcsPerDay: null,
    UID: null,
    UpdateDate: null,
    CreateDate: null,
    DeleteDate: null
  }
  proxy.resetForm("moldingRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加注塑件成本"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getMolding(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改注塑件成本"
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["moldingRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateMolding(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addMolding(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row,index) {
  // if(row.isAdd){
  //    moldingList.value.splice(index,1)
  //    proxy.$modal.msgSuccess("删除成功")
  // }else{
  const _ids = row.id || ids.value
  proxy.$modal.confirm('是否确认删除注塑件成本编号为"' + _ids + '"的数据项？').then(function() {
    return delMolding(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {})
  // }

}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('system/molding/export', {
    ...queryParams.value
  }, `molding_${new Date().getTime()}.xlsx`)
}

getList()
</script>
<style scoped>
:deep(.el-table thead.is-group > tr:first-child th) {
  height: 25px !important;
  line-height: 25px !important;
  padding: 0 !important;
  background-color: #f5f5f5;
}

/* 二级表头样式 */
:deep(.el-table thead.is-group > tr:last-child th) {
  height: 25px !important;
  line-height: 25px !important;
  padding: 0 !important;
}

/* 单元格内容居中 */
:deep(.el-table__header-cell .cell) {
  line-height: 25px;
  display: flex;
  align-items: center;
  justify-content: center;
}
:deep(.el-table thead.is-group > tr:last-child th) {
  background-color: #f5f5f5 !important; /* 第二层背景色 */
}
.calculate{
  margin-top: 30px;
  font-size: 14px;
}
.calculate .el-row {
  height: 55px;
}
.dialog-content{
  padding:50px
}
.layoutStyle{
  display: flex;
  flex-direction: row;
  .leftStyle{
    width: 65%;
   }
  .rightStyle{
    width: 35%;
  }
  ul, ol {
  list-style-type: none; /* 移除所有列表的默认标记 */
  padding-left: 0; /* 移除默认的左缩进 */
  margin-left: 0;
  }
  ol {
    height: 140px;
  }

.titleDiv{
     font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
     font-size: 14px; /* 正文标准 */
     line-height: 1.5; /* 推荐 1.4-1.6 */
     color: #555; /* 主文字 */
     font-weight: 400; /* 正常 */
     text-align: left; /* 对齐方式 */
     letter-spacing: 0; /* 字间距 */
     margin-top: 5px;
}

.flexdiv{
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  height: 35px;
}
.ellipsis-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}
/* el-table 内容居中对齐 */
:deep(.el-table .cell) {
  text-align: center;
  justify-content: center;
}

/* Center header content */
:deep(.el-table__header-cell .cell) {
  text-align: center;
  justify-content: center;
}
:deep(.el-table__cell) {
  padding: 0 !important;
}

/* Specifically target data cells */
:deep(.el-table__body .el-table__cell) {
  padding: 0 !important;
}

/* Specifically target header cells */
:deep(.el-table__header .el-table__cell) {
  padding: 0 !important;
}

/* Adjust cell content alignment */
:deep(.el-table .cell) {
  padding: 10 1px; /* Adjust as needed */
}

}
</style>